//
//  InfoSendViewController.m
//  YiFei
//
//  Created by maquanhong on 10/23/16.
//  Copyright © 2016 yous. All rights reserved.
//

#import "InfoSendViewController.h"
#import "SendDataViewCell.h"


@interface InfoSendViewController ()<UITableViewDataSource, UITableViewDelegate,UITextFieldDelegate>
{
    SendDataViewCell *cell;
}

@property (nonatomic, strong) UITextField   *textField;
@property (nonatomic, strong) UITableView   *tableView;
@property (nonatomic, strong) NSArray       *sendArray;
@property (nonatomic, strong) NSArray       *dataArray;
@property (nonatomic, strong) NSArray  *TitleArray;

@end


@implementation InfoSendViewController


- (void)viewDidLoad {
    [super viewDidLoad];
     [self createNavigationView];
    _TitleArray = [[NSArray alloc] initWithObjects:@"发送方式",@"资料格式", nil];
    _sendArray  = @[@{@"发送方式":@"蓝牙发送"},@{@"发送方式":@"Email发送"}];
     _dataArray  = @[@{@"发送方式":@"Excel"},@{@"发送方式":@"PDF"}];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self addViewConstraints];
 
}


#pragma mark 创建navgationView
-(void)createNavigationView
{
      self.navigationItem.title = @"商品资料发送";
    BackButton *leftBtn = [[BackButton alloc] initWithFrame:CGRectMake(0, 0, 12, 20)];
    [leftBtn setBackgroundImage:[UIImage imageNamed:@"fanhui_icon"] forState:UIControlStateNormal];
    UIBarButtonItem * barItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    self.navigationItem.leftBarButtonItem = barItem;
    [leftBtn addTarget:self action:@selector(leftButtonClick) forControlEvents:UIControlEventTouchUpInside];
}

-(void)leftButtonClick{
    [self.navigationController popViewControllerAnimated:YES];
    
}

#pragma mark 添加视图
- (void)addViewConstraints {

    _textField = [[UITextField alloc] init];
    _textField.font = [UIFont systemFontOfSize:14];
    _textField.delegate = self;
    _textField.layer.borderWidth = 1;
    _textField.layer.borderColor = COLOR.CGColor;
    _textField.layer.cornerRadius = 5.0;
    _textField.layer.masksToBounds =YES;
    _textField.placeholder = @"输入设备号或地址";
    [self.view addSubview:_textField];
    [_textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).offset(74);
        make.leading.mas_equalTo(self.view).offset(30);
        make.trailing.mas_equalTo(self.view).offset(-30);
        make.height.mas_equalTo(25);
    }];
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 110, WIDTH, HEIGHT) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 60)];
    UIButton *btn = [[UIButton alloc] init];
    [btn setTitle:@"发送" forState:UIControlStateNormal];
    btn.layer.cornerRadius = 5;
    btn.backgroundColor = NAVCOLOR;
    [footerView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(footerView).offset(50);
        make.trailing.mas_equalTo(footerView).offset(-50);
        make.centerY.mas_equalTo(footerView.mas_centerY);
        make.height.mas_equalTo(30);
    }];
    _tableView.tableFooterView  = footerView;
    
}


#pragma mark tableView 的代理方法

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _TitleArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section== 0) {
        return _sendArray.count;
    }else{
        return _dataArray.count;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
 
    if (indexPath.section == 0) {
        static NSString *identifer1 = @"sendCell";
        cell  = [tableView dequeueReusableCellWithIdentifier:identifer1];
        if (cell == nil) {
            cell = [[SendDataViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer1];
        }
        cell.dict  =  [NSDictionary  dictionaryWithDictionary:_sendArray[indexPath.row]];
       cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        return cell;
    }else{
        static NSString *identifer2 = @"firstCell";
        cell  = [tableView dequeueReusableCellWithIdentifier:identifer2];
        if (cell == nil) {
            cell = [[SendDataViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifer2];
        }
    cell.dict = [NSDictionary dictionaryWithDictionary:_dataArray[indexPath.row]];
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    return cell;
    }
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}


-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        UIView *headerOneView =  [self infoSendTableView:_TitleArray[0]];
        return headerOneView  ;
    }else{
        UIView *headerTwoView = [self infoSendTableView:_TitleArray[1]];
        return headerTwoView;
    }
}


- (UIView *)infoSendTableView:(NSString *)title {

         UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 50)];
         headView.backgroundColor = [UIColor grayColor];
         UILabel *titleLabel = [[UILabel alloc] init];
         titleLabel.text = title;
         titleLabel.font = [UIFont systemFontOfSize:14];
         [headView addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.leading.mas_equalTo(headView).offset(20);
            make.centerY.mas_equalTo(headView.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(100, 20));
        }];
    return headView;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 50;
}











@end












